#include "ipc_common.hpp"
#include <iostream>

bool WriteMessage(const HANDLE pipe, const std::string& message) {
    Message msg{};
    message.copy(msg.data, message.length());
    msg.length = message.length();

    DWORD bytesWritten;
    return WriteFile(pipe, &msg, sizeof(Message), &bytesWritten, nullptr) != 0;
}

std::string ReadMessage(const HANDLE pipe) {
    Message msg{};
    DWORD bytesRead;

    if (ReadFile(pipe, &msg, sizeof(Message), &bytesRead, nullptr)) {
        return std::string(msg.data, msg.length);
    }
    return "";
}
